/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.geergenbein.azw.dao.transcription;

import javax.persistence.EntityManager;
import org.geergenbein.azw.model.transcription.Dialect;
import org.geergenbein.azw.model.transcription.TranscriptionSystem;
import org.geergenbein.dao.GenericHibernateDAO;

/**
 *
 * @author andrew
 */
public class TranscriptionSystemDAOHibernate extends GenericHibernateDAO<TranscriptionSystem, Long> {
    
    public TranscriptionSystemDAOHibernate(EntityManager em) {
        super(em);
    }
    
    public TranscriptionSystem find(Dialect dialect, 
            String name) 
    {
        return (TranscriptionSystem) getSession().
                getNamedQuery("findTranscriptionSystem").
                setParameter("dialect", dialect).
                setParameter("name", name).
                uniqueResult();
    }
    
    public TranscriptionSystem loadOrPersist(Dialect dialect, String name) {
        TranscriptionSystem ts = null;
        if ((ts = find(dialect, name)) == null) {
            ts = new TranscriptionSystem(dialect, name);
            makePersistent(ts);
            log.debug("Persisted transcription system: " + ts);
        } else {
            log.debug("Found transcription system: " + ts);
        }
        return ts;
    }
    
}
